/*
 * @Author: your name
 * @Date: 2021-05-19 17:22:23
 * @LastEditTime: 2021-05-31 17:43:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/home/scheduModal/index.tsx
 */
import { IFormTypeEnum } from '@/components/form/formComponent';
import { FormInstance, Modal } from 'antd';
import HeaderForm from '@/components/form';
import React, { useEffect } from 'react';
import { edit_project, add_project } from '../../../services/pages';
import { globalModel } from '@/pages/globalModel';

interface IProps {
  visible: boolean;
  close: () => void;
  refresh: () => void;
  row?: any;
}

const ProjectModal = (props: IProps) => {
  const List = [
    // {
    //   key: 'store_id',
    //   type: IFormTypeEnum.Select,
    //   label: '门店',
    //   rules: [{ required: true }],
    //   data: {
    //     list: globalModel.storeList,
    //     fieldNames: { value: 'store_id', label: 'store_name' },
    //   },
    // },
    {
      key: 'project_name',
      type: IFormTypeEnum.Input,
      label: '项目名称',
      rules: [{ required: true }],
    },
    {
      key: 'origin_price',
      type: IFormTypeEnum.InputNumber,
      label: '项目价格',
      rules: [{ required: true }],
    },
    {
      key: 'during',
      type: IFormTypeEnum.InputNumber,
      label: '项目时长（分钟）',
      rules: [{ required: true }],
    },
    {
      key: 'vip_one',
      type: IFormTypeEnum.InputNumber,
      label: '黄金会员价格',
      rules: [{ required: true }],
    },
    {
      key: 'vip_two',
      type: IFormTypeEnum.InputNumber,
      label: '铂金会员价格',
      rules: [{ required: true }],
    },
    {
      key: 'vip_three',
      type: IFormTypeEnum.InputNumber,
      label: '钻石会员价格',
      rules: [{ required: true }],
    },
    {
      key: 'staff_price',
      type: IFormTypeEnum.InputNumber,
      label: '员工提成',
      rules: [{ required: true }],
    },
  ];

  const onFinish = async (values: any, form: FormInstance) => {
    values.origin_price = values.origin_price * 100;
    values.vip_one = values.vip_one * 100;
    values.vip_two = values.vip_two * 100;
    values.vip_three = values.vip_three * 100;
    values.staff_price = values.staff_price * 100;

    if (props.row?.project_id) {
      await edit_project({ ...values, project_id: props.row?.project_id });
    } else {
      await add_project(values);
    }
    props.close();
    props.refresh();
  };

  useEffect(() => {
    globalModel.getStores();
  }, []);

  return (
    <Modal
      className="projectModal"
      maskClosable={false}
      visible={props.visible}
      title={props.row?.project_id ? '编辑项目' : '添加项目'}
      footer={null}
      onCancel={props.close}
    >
      <HeaderForm
        labelwidth={120}
        layout="horizontal"
        list={List}
        onSubmit={onFinish}
        initialValues={{
          project_name: props.row?.project_name,
          during: props.row?.during / 60,
          origin_price: props.row?.origin_price / 100,
          vip_one: props.row?.vip_one / 100,
          vip_two: props.row?.vip_two / 100,
          vip_three: props.row?.vip_three / 100,
          staff_price: props.row?.staff_price / 100,
        }}
      />
    </Modal>
  );
};
export default ProjectModal;
